package com.freejy.ecommunity.service;

import com.freejy.ecommunity.mapper.SysConfigMapper;
import com.freejy.ecommunity.model.SysConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Jerry
 */
@Service
public class SysConfigService
{

    @Autowired
    private SysConfigMapper sysConfigMapper;

    /**
     * add sys config
     * @param model
     * @return
     */
    public boolean save(SysConfig model)
    {
        boolean res = false;
        if (model != null)
        {
            int cnt = sysConfigMapper.insertSelective(model);
            if (cnt > 0)
            {
                //TODO add cache
                res = true;
            }
        }
        return res;
    }

    /**
     * update sys config
     * @param model
     * @return
     */
    public boolean update(SysConfig model)
    {
        boolean res = false;
        if (model != null) {
            int cnt = sysConfigMapper.updateByPrimaryKeySelective(model);
            if (cnt > 0) {
                //TODO update cache
                res = true;
            }
        }
        return res;
    }

    /**
     * find all
     * @return
     */
    public List<SysConfig> findAll()
    {
        //TODO add cache
        return sysConfigMapper.findAll();
    }

    /**
     * find by category
     * @param category
     * @return
     */
    public List<SysConfig> findByCategory(String category)
    {
        return sysConfigMapper.findByCategory(category);
    }

    /**
     * find by name
     * @param name
     * @return
     */
    public SysConfig findByName(String name)
    {
        return sysConfigMapper.findByName(name);
    }

}
